package processing_layer;

import java.util.ArrayList;

import database_layer.UpdateDispatcher;

/**
 * This class is used in order to inject demo values to the DB.
 * The return values from the DB layer are ignored, since if these entries
 * already exists, the DB won't continue with the insertion, and we won't
 * receive an error / exception (Like key duplication, for example)
 */
public class Demo
{
	public static void insertDemoValues()
	{
		// Two users
		User u1 = new User("u1","1","first","name","12345","none",false,null);
		User u2 = new User("u2","2","name","first","54321","enon",false,null);
		
		// Two admins
		User a1 = new User("a1","1","ad","min","911","lab",true,null);
		User a2 = new User("a2","2","min","ad","199","bal",true,null);
		
		// Course by a1
		Course c1 = new Course("Introduction to math","Very boring",2,5,0,1,"a1");
		
		// Course by a2
		Course c2 = new Course("Advanced thinking","Includes a lot of math",3,10,0,2,"a2");
		
		// Course by a2
		Course c3 = new Course("Primitive thinking","Includes thinking...",2,5,0,2,"a2");
		
		// Sessions for c1
		CourseSession c1_s1 = new CourseSession("Introduction to math", 1, 8, 10, 2, 1);
		CourseSession c1_s2 = new CourseSession("Introduction to math", 2, 10, 12, 2, 1);
		CourseSession c1_s3 = new CourseSession("Introduction to math", 3, 12, 16, 4, 1);
		ArrayList<CourseSession> c1_s = new ArrayList<CourseSession>();
		c1_s.add(c1_s1);
		c1_s.add(c1_s2);
		c1_s.add(c1_s3);
		
		// Sessions for c2
		CourseSession c2_s1 = new CourseSession("Advanced thinking", 1, 9, 11, 2, 2);
		CourseSession c2_s2 = new CourseSession("Advanced thinking", 3, 13, 15, 2, 2);
		ArrayList<CourseSession> c2_s = new ArrayList<CourseSession>();
		c2_s.add(c2_s1);
		c2_s.add(c2_s2);
		
		// Sessions for c3
		CourseSession c3_s1 = new CourseSession("Primitive thinking", 4, 8, 10, 2, 2);
		CourseSession c3_s2 = new CourseSession("Primitive thinking", 5, 8, 10, 2, 2);
		CourseSession c3_s3 = new CourseSession("Primitive thinking", 7, 8, 12, 4, 2);
		ArrayList<CourseSession> c3_s = new ArrayList<CourseSession>();
		c3_s.add(c3_s1);
		c3_s.add(c3_s2);
		c3_s.add(c3_s3);
		
		// We ignore the return values from the UpdateDispatcher
		// since it won't insert these values if they already exist
		// it will only "fill the gaps"
		UpdateDispatcher.addUser(u1);
		UpdateDispatcher.addUser(u2);
		UpdateDispatcher.addUser(a1);
		UpdateDispatcher.addUser(a2);
		UpdateDispatcher.addCourseAndSessions(c1, c1_s);
		UpdateDispatcher.addCourseAndSessions(c2, c2_s);
		UpdateDispatcher.addCourseAndSessions(c3, c3_s);
			
		// Register u1 to c2 and c3
		UpdateDispatcher.registerUserToCourse("u1", "Advanced thinking");
		UpdateDispatcher.registerUserToCourse("u1", "Primitive thinking");
			
		// Register u2 to c1
		UpdateDispatcher.registerUserToCourse("u2", "Introduction to math");
	}
}
